import { ref } from 'vue'
export default function (index) {
  const refpassw = ref(null)
  const password = ref('')
  let myindex = ref(-1)
  let eye = ref(false)

  function changPattern(e) {
    let value = e.target.value
    if (value.length > password.value.length) {
      password.value += value[value.length - 1]
    } else {
      password.value = password.value.substring(0, value.length)
    }
    if (!eye.value) e.target.value = value.replaceAll(/./g, '*')
    if (e.target.value.length <= 6) {
      index ? (index.value = 0) : (myindex.value = 0)
    } else if (e.target.value.length <= 12) {
      index ? (index.value = 1) : (myindex.value = 1)
    } else {
      index ? (index.value = 2) : (myindex.value = 2)
    }
  }
  function changEye() {
    eye.value = !eye.value
    eye.value
      ? (refpassw.value.value = password.value)
      : (refpassw.value.value = password.value.replaceAll(/./g, '*'))
    console.log(password.value)
  }
  return {
    changEye,
    eye,
    password,
    changPattern,
    refpassw,
    index: myindex
  }
}
